function saveRow( form ) {

   var myCallback = callback;
   myCallback.setForm(form);
   myCallback.processSuccess = function (json) {
      addRow(this.form.id, json);
   };
   
   var cObj = YAHOO.util.Connect.asyncRequest('POST', form.action, myCallback); 
   
   /* Because different browsers are screwy with memory, I'm cleaning it up */
   myCallback = form = null;
   
   return false;
}

function addRow ( rowName, data ) {
   
   table = document.getElementById(rowName + "List");
   tbody = table.getElementsByTagName('tbody')[0];
   
   tr = document.createElement('tr');
   tr.setAttribute('id', rowName + "_" + data.id);
   tr.style.setProperty('opacity', 0, null); // Hide it to start.
   
      // Properly alternate the colours!
   lastChild = YAHOO.util.Dom.getLastChild(tbody);
   
   if ( lastChild != null ) {
      class = lastChild.getAttribute('class');
      
      if ( class.search(/odd/) != -1 )  {
         YAHOO.util.Dom.addClass(tr, 'even');
      } else {
         YAHOO.util.Dom.addClass(tr, 'odd');
      }
      class = null;
   } else {
      YAHOO.util.Dom.addClass(tr, 'even');
   }
   
   lastChild = null;
   
   // Everybody has a "name" column
   td = document.createElement('td');
   td.innerHTML = data.name;
   tr.appendChild(td);
   
   // Columns unique to the specific tables.
   switch ( rowName ) {
      case 'stat':
         // Min value Column
         td = document.createElement('td');
         td.innerHTML = data.min_value;
         tr.appendChild(td);
         
         // Max Value column
         td = document.createElement('td');
         td.innerHTML = data.max_value;
         tr.appendChild(td);
         break;
      case 'guild':
         // Server Name column
         td = document.createElement('td');
         td.innerHTML = data.server_name;
         tr.appendChild(td);
         break;
   }
   
   // Building the image and href for handing the "delete" link
   /* Img Tag */
   img = document.createElement('img');
   img.setAttribute('src', deleteImg.src);
   img.setAttribute('border', 0);
   img.setAttribute('id', rowName + "_" + data.id + "_img");
   
   /* href tag */
   a = document.createElement('a');
   a.setAttribute('href', '/admin/'+ rowName + '/delete/id/' + data.id);
   a.onclick = function() { deleteRow(rowName, data.id); return false; };
   
   a.appendChild(img); // Add IMG tag into A tag. 
   img = null;
   
   /* Final data cell */
   td = document.createElement('td');
   td.style.setProperty('text-align', 'center', null);
   td.appendChild(a);
   tr.appendChild(td);
   tbody.appendChild(tr);
   a = td = null
   
   var fadeIn = new YAHOO.util.Anim(tr, {
                     opacity: {from: 0, to: 100},
                     }, 0.5);
                        
   fadeIn.animate();
   
   YAHOO.util.Selector.query(rowName, 'input')[0].value = '';
   //document.getElementById(rowName).reset();
   
   tbody = tr = null;
}


function deleteRow( table, id ) {
   var imageBnt = YAHOO.util.Dom.get(table+"_"+id+"_"+"img");
   
   var url = "/admin/" + table + "/delete";
   
   var myCallback = callback;
   myCallback.start = function() {
      if ( imageBnt ) {
         imageBnt.src = loadingImg.src;
      }
   };
   
   myCallback.processSuccess = function ( json ) {
      var tmp = YAHOO.util.Dom.get(table+"_"+id);
      var fadeOut = new YAHOO.util.Anim(tmp, {
                           opacity: {to: 0},
                           }, 0.5);
                           
      fadeOut.onComplete.subscribe(function(){
                                    YAHOO.util.Dom.setStyle(tmp,
                                    'display', 'none')});
      fadeOut.animate();
      fadeOut = null;
   }
   
   var cObj = YAHOO.util.Connect.asyncRequest('POST', url, callback, "&id="+id+"&signature="+signature);
   
   cObj = myCallback = url = imageBnt = row = null;
   
   return false;
}

